﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BLL
{
    public class FormacaoAcademica
    {
        public class entFormacoes
        {
            private string idFormacao;
            public string IdFormacao
            {
                get { return idFormacao; }
                set { idFormacao = value; }
            }

            private string formacao;
            public string Formacao
            {
                get { return formacao; }
                set { formacao = value; }
            }
        }
        
        public DataTable ListaFormacoes()
        {
            string procName = "stpFormacoesAcademicas";
            List<SqlParameter> parameter = new List<SqlParameter>();
            parameter.Add(new SqlParameter("@Operacao", 1));

            DataTable dt = new DataTable();
            return dt = DAL.DAL.ExecSPWithReturn(parameter, procName);
        }

        public entFormacoes CarregaDetalhesDaFormacao(string idFormacao)
        {
            string procName = "stpFormacoesAcademicas";
            List<SqlParameter> parameter = new List<SqlParameter>();
            parameter.Add(new SqlParameter("@Operacao", 4));
            parameter.Add(new SqlParameter("@IDFormacao", idFormacao));

            entFormacoes form = new entFormacoes();
            
            DataTable dt = new DataTable();
            dt = DAL.DAL.ExecSPWithReturn(parameter, procName);

            if (dt != null)
            {
                form.Formacao = dt.Rows[0]["Formacao"].ToString();
                form.IdFormacao = dt.Rows[0]["IDFormacao"].ToString();
            }
            
            return form;
        }

        public entFormacoes InsereFormacaoAcademica(entFormacoes form)
        {
            string procName = "stpFormacoesAcademicas";
            List<SqlParameter> parameter = new List<SqlParameter>();
            parameter.Add(new SqlParameter("@Operacao", 2));
            parameter.Add(new SqlParameter("@Descricao", form.Formacao));

            DataTable dt = new DataTable();
            dt = DAL.DAL.ExecSPWithReturn(parameter, procName);

            if (dt != null)
                form.IdFormacao = dt.Rows[0]["IDFormacao"].ToString();

            return form;
        }

        public void AtualizaFormacaoAcademica(entFormacoes form)
        {
            string procName = "stpFormacoesAcademicas";
            List<SqlParameter> parameter = new List<SqlParameter>();
            parameter.Add(new SqlParameter("@Operacao", 3));
            parameter.Add(new SqlParameter("@Descricao", form.Formacao));
            parameter.Add(new SqlParameter("@IDFormacao", form.IdFormacao));
            
            DAL.DAL.ExecSPWithReturn(parameter, procName);
        }
    }
}
